<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/inc/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>商品信息</title>
		<link type="text/css" href="/css/jquery-ui/jquery.ui.all.css" rel="stylesheet" />
		<link href="/css/common.css" rel="stylesheet" type="text/css" />
		<style type="text/css">
			body{
				font:12px/1.75 Tahoma,Arial;color:#333;
			}
		</style>
		<script type="text/javascript" src="${path }/js/jquery-1.4.2.min.js"></script>
		<script type="text/javascript" src="/js/jquery-ui/jquery.ui.core.js"></script>
		<script type="text/javascript" src="/js/jquery-ui/jquery.ui.widget.js"></script>
		<script type="text/javascript" src="/js/jquery-ui/jquery.ui.tabs.js"></script>
		<script type="text/javascript">
			var path="${path}";
			var source_url = "/goods/auction/memberList?goodsNo=${goods.goodsNo}";
		</script>
		<script type="text/javascript" src="${path }/js/form/jquery.form.js"></script>
		<script type="text/javascript" src="/js/app/auction.js"></script>
		
		<script type="text/javascript">
				var obj;
				//取开始时间.
				var startyear = ${startyear};
				var startmonth = ${startmonth};
				var startday = ${startday};
				var starthour = ${starthour};
				var startmin = ${startmin};
				var startsec = ${startsec};
					
				//取服务器端现在时间.
				var nowyear = ${nowyear};
				var nowmonth = ${nowmonth};
				var nowday = ${nowday};
				var nowhour = ${nowhour};
				var nowmin = ${nowmin};
				var nowsec = ${nowsec};
					
				var nowtime;
				var started = false;
			
				//开始初始化。
				function start(){
					var nowDate  = new Date(nowyear,nowmonth,nowday,nowhour,nowmin,nowsec);
					nowtime = nowDate.getTime();
					compDate();
				}
				
				
				//日期比较.
				function compDate(){
					
					var timediv = document.getElementById("timeDown");
					var startDate = new Date(startyear,startmonth,startday,starthour,startmin,startsec);
					nowtime = nowtime + 1000;
					var starttime = startDate.getTime();
					
					var left=Math.floor((starttime-nowtime)/1000);
					if(left > 0){
						d=Math.floor(left/3600/24);
						h=Math.floor((left/3600)%24);
						m=Math.floor((left/60)%60);
						s=Math.floor(left%60);
						timediv.innerHTML=d+"天"+h+"小时"+m+"分"+s+"秒";
					}else if(left==0){
						clearTimeout(obj);
						started=true;
						downTime(${mincount});
						return;
					}else{
						clearTimeout(obj);
						downTime1();
						return;
					}
					obj = setTimeout("compDate()",1000);
				}
				
				var startt;
				var endt;
				//开始后的倒计时.
				function downTime(mincount){
					var start = new Date(startyear,startmonth,startday,starthour,startmin,startsec);
					startt=start.getTime();
					var end  = new Date(startyear,startmonth,startday,starthour,startmin+mincount,startsec);
					endt=end.getTime();
					
				
					down();
				}
				
				function downTime1(){
					var start = new Date(nowyear,nowmonth,nowday,nowhour,nowmin,nowsec);
					startt=start.getTime();
					var end  = new Date(startyear,startmonth,startday,${endhour},${endmin},${endsec});
					endt=end.getTime();
					if(Math.floor((endt-startt)/1000)>0){
						started=true;
					}
				
					down();
				}
				
				//拍卖倒计时.
				function down(){
					var timediv = document.getElementById("timeDown");
					startt =startt+1000;
					var diff = Math.floor((endt-startt)/1000);
					if(diff > 0){
						h=Math.floor((diff/3600)%24);
						m=Math.floor((diff/60)%60);
						s=Math.floor(diff%60);
						timediv.innerHTML="剩余:"+h+"小时"+m+"分"+s+"秒";
					}else if(diff==0){
						timediv.innerHTML="拍卖结束";
						timeOut();
						clearTimeout(obj);
						return;
					}else{
						timediv.innerHTML="拍卖结束";
						$("#auctionPrice").attr("disabled",true);
						$("#butAuction").attr("disabled",true);
					}
					obj = setTimeout("down()",1000);
				}
				
				//拍卖加价.
				function addPrice(){
					if(started==false){
						alert("拍卖未开始!");
						return;
					}else{
						var auctionPrice = $("#auctionPrice").val();
						var memberId = $("#memberId").val();
						$.post(
							"/goods/auction/addPrice?goodsNo=${goods.goodsNo}&memberId="+memberId+"&auctionPrice="+auctionPrice,
							function(json){
								if(json.result=="Success"){
									$("#info").html("出价成功!");
								}
								if(json.result=="Faile"&&json.ErrorCode == "-1"){
									$("#info").html("您未登录，请先登录!");
								}
								if(json.result=="Faile"&&json.ErrorCode == "-2"){
									$("#info").html("您出的价比上一人低哦！");
								}
								if(json.result=="Faile"&&json.ErrorCode == "-3"){
									$("#info").html("您所出价小于最低加价");
								}
								if(json.result=="Faile"&&json.ErrorCode == "-4"){
									$("#info").html("您所出价高于最高加价");
								}
							},
							"json"
						);
					}
				}
				
				//拍卖结束.
				function timeOut(){
					$("#auctionPrice").attr("disabled",true);
					$("#butAuction").attr("disabled",true);
					$.post(
						"/goods/auction/timeOut/${goods.goodsNo}",
						function(json){
							if(json.result=="Success"){
								$("#info").html("拍卖由 "+json.lastAuction.memberName+" 成功拍得")
							}
						},
						"json"
					);
				}
			
				$(function() {
					$("#tabs").tabs();
					start();
					
					template = '<dd id="{id}"><div style="width:350px;"><div style="float:left;width:100px;">{memberName}</div><div style="float:left;width:100px;">{auctionPrice}</div><div style="float:left;width:150px;">{date}</div></div></dd>';
		  			t_update(template,4);
				});
		</script>
	</head>
	<body>
		<!-- 前端商品基本信息 -->
		<div class="front_goods_info">
			<p>${goods.goodsName }</p>
			<div class="front_goods_img">
				<img src="/picture/show/${goods.goodsImg }" >
			</div>
			<div class="front_goods_base">
				<div>
					商品编号:${goods.goodsNo }
				</div>
				<div>
					市场价:￥${goods.marketPrice }
				</div>
				<div>
					本店价:￥${goods.shopPrice }
				</div>
				<div>
					库存:${goods.goodsStock }
				</div>
				<div>
					起拍价:${goods.auctionStartPrice }
				</div>
				<div>
					最底加价:${goods.minAdd }
				</div>
				<div>
					最高加价:${goods.maxAdd }
				</div>
				
			</div>
		</div>
		<br/>
		<!-- 拍卖倒计时 -->
		<div class="front_goods_downtime">
			<div class="auction_fun">
				<div id="timeDown">time</div>
				<input type="hidden" name="memberId" id="memberId" value="${member.memberId }">
				<input type="text" name="auctionPrice" id="auctionPrice" >
				<input type="button" id="butAuction" value="出价" onclick="addPrice()">
				<div id="info">
				
				</div>
			</div>
			<div id="act_list" class="auction_list">
				<dt class="txt_blue">
					最新出价
				</dt>
			</div>
		</div>
		
		</br>
		<!-- 前端商品详细信息 -->
		<div class="front_goods_cont">
			<div id="tabs">
				<ul>
					<li><a href="#tab1">商品详细信息</a></li>
					<li><a href="#tab2">商品评论</a></li>
					<li><a href="#tab3">商品属性</a></li>
				</ul>
				<div id="tab1" class="front_goods_cont_txt">
					${goods.goodsDesc.value }
				</div>
				<div id="tab2" class="front_goods_cont_txt">
					暂无信息
				</div>
			</div>
			
		</div>
	</body>
</html>